<?php if ( !defined('BASEPATH')) exit('No direct script access allowed');

class Lookup extends CI_Controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('wus');
        $this->load->model($this->session->userdata('formodel'));
        $this->load->library('variable');

    }
    public function index(){
      $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
      $this->load->view($this->session->userdata('formain'));
      $this->load->view('layouts/footer');
     }

    public function search(){
        $code = $this->input->post('code');
        $q = $this->lookup_model->getResult($code);
        echo json_encode($q);
    }

    public function add_form(){
        $this->load->view($this->session->userdata('foradd'));
    }

    public function insertLookUp()
    {
        $data = array(
            ':p_lookup_type'    =>  $this->input->post('lookup_type'),
            ':p_description'    =>  $this->input->post('lookup_desc'),
            ':p_enable_flag'    =>  ($this->input->post('enableBox') == "ok" ? 'Y' : 'N'),
            ':p_user_id'        =>  $this->session->userdata('user_id')
        );
        $this->lookup_model->storeLookUp($data); 
    }

    public function updateLookUp()
    {
        $data = array(
            ':p_lookup_type'    =>  $this->input->post('LookUpCode'),
            ':p_description'    =>  $this->input->post('moduleName'),
            ':p_enable_flag'    =>  ($this->input->post('LookUpEnableFlag') == "ok" ? 'Y' : 'N'),
            ':p_user_id'        =>  $this->session->userdata('user_id')
        );
        $this->lookup_model->putLookUp($data); 
    }

    public function insertLookUpValues()
    {
        $data = array(
            ':p_lookup_type'    =>  $this->input->post('LookUpType'),
            ':p_lookup_code'    =>  $this->input->post('LookUpCode'),
            ':p_meaning'        =>  $this->input->post('LookUpMeaning'),
            ':p_description'    =>  $this->input->post('LookUpDesc'),
            ':p_enable_flag'    =>  ($this->input->post('LookUpEF') == "ok" ? 'Y' : 'N'),
            ':p_user_id'        =>  $this->session->userdata('user_id')
        );
        $this->lookup_model->storeLookUpValues($data);
    }

    public function updateLookUpValues()
    {
        $data = array(
            ':p_lookup_type'    =>  $this->input->post('LookUpType'),
            ':p_lookup_code'    =>  $this->input->post('LookUpCode'),
            ':p_meaning'        =>  $this->input->post('LookUpMeaning'),
            ':p_description'    =>  $this->input->post('LookUpDesc'),
            ':p_enable_flag'    =>  ($this->input->post('LookUpEF') == "ok" ? 'Y' : 'N'),
            ':p_user_id'        =>  $this->session->userdata('user_id')
        );
        $this->lookup_model->putLookUpValues($data); 
    }

    public function edit_form($id){
            $lookup = $this->lookup_model->getLookUp($id);
            $this->load->view($this->session->userdata('foredit'),array(
                    'result'    =>  $lookup,
                ));
    }

    public function getLookUpValues(){
        $id = $this->input->post('lookuptype');
        $lookupvalues = $this->lookup_model->getLookUpValues($id);
        echo json_encode($lookupvalues);
    }

    public function view_form($id){
            $lookup = $this->lookup_model->getLookUp($id);
            $lookupvalues = $this->lookup_model->getLookUpValues($id);
            $this->load->view($this->session->userdata('forview'),array(
                    'lookup'        =>$lookup,
                    'lookupvalues'   => $lookupvalues
                ));
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */